package com.hjq.config;

import com.hjq.interceptor.DemoInterceptor;
import com.hjq.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
// 声明这是一个配置类
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Override
    // 添加注册拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        // 注入了一个TokenInterceptor拦截器实例
        // /** 拦截所有路径的请求，排除/login
        registry.addInterceptor(tokenInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/login");
    }
}
